﻿using UnityEngine;
using System.Collections;

public enum ShipType
{
	SmallShip = 0, MediumShip = 1, LargeShip = 2
}

public enum WeaponType
{
	Ballistics = 0, Missle = 1, Laser = 2
}

public class PlayerStats : MonoBehaviour 
{
	public int Hull; //Health
	public int Shield; //Shield Strength
	public int Armor; //Defense
	public int Skill; //Accuracy
	public int Firepower; //Strength
	public int Evasion; //Speed
	public int Luck; //Luck
	
	public int HullGrowth;
	public int ShieldGrowth;
	public int ArmorGrowth;
	public int SkillGrowth;
	public int FirepowerGrowth;
	public int EvasionGrowth;
	public int LuckGrowth;
	
	public ShipType shipType;
	public WeaponType weaponType;
	
	public int TerrainBonus;
	
	// Use this for initialization
	void Start () 
	{
		//Check if each one is initialized
	}
	
	// Update is called once per frame
	void Update () 
	{
	
	}
	
	public int HitPercentage(ShipType enemyShipType)
	{
		if ((shipType == ShipType.SmallShip && enemyShipType == ShipType.MediumShip) ||
			(shipType == ShipType.MediumShip && enemyShipType == ShipType.LargeShip) ||
			(shipType == ShipType.LargeShip && enemyShipType == ShipType.SmallShip))
		{
			return 100 + Skill*2 + Luck;
		}
		else if ((shipType == ShipType.SmallShip && enemyShipType == ShipType.LargeShip) ||
			(shipType == ShipType.LargeShip && enemyShipType == ShipType.MediumShip) || 
			(shipType == ShipType.MediumShip && enemyShipType == ShipType.SmallShip))
		{
			return 70 + Skill*2 + Luck;
		}
		else
		{
			return 85 + Skill*2 + Luck;
		}
	}
	
	public int CalculateDamage()
	{
		if (Random.Range(0, 100) < Luck)
			return Firepower * 3;
		else
			return (int)(Firepower * 1.5);
	}
	
	public int EvadePercentage()
	{
		return Evasion * 2 + Luck + TerrainBonus;
	}
	
	public int DamageDone(int calculatedDamage)
	{
		return calculatedDamage - Armor;
	}
	
	public void DealDamage(int damage, WeaponType weapon)
	{
		if (Shield > 0)
		{
			if (weapon == WeaponType.Missle)
			{
				Shield -= damage/4;
				if (Shield < 0)
					Shield = 0;
				
				Hull -= damage/4;
				if (Hull < 0)
					Hull = 0;
			}
			
			if (weapon == WeaponType.Ballistics)
			{
				Shield -= damage/8;
				if (Shield < 0)
					Shield = 0;
			}
			
			if (weapon == WeaponType.Laser)
			{
				Shield -= damage;
			}
			
		}
		else
		{
			if (weapon == WeaponType.Missle)
			{
				Hull -= damage;
				if (Hull < 0)
					Hull = 0;
			}
			
			if (weapon == WeaponType.Ballistics)
			{
				Hull -= damage;
				if (Hull < 0)
					Hull = 0;
			}
			
			if (weapon == WeaponType.Laser)
			{
				Hull -= damage/8;
				if (Hull < 0)
					Hull = 0;
			}
		}
	}
	
}
